package com.qutan.app;

import com.qutan.app.core.cache.InfoCache;
import com.qutan.app.core.cache.SceneCache;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;

/**
 * Created by pwy on 14-6-17.
 */
@SpringBootApplication
@EnableAutoConfiguration(exclude = {FreeMarkerAutoConfiguration.class})
@EnableTransactionManagement
@EnableScheduling
@ImportResource({"classpath:dubboProvider.xml"}) //加入spring的bean的xml文件*/
public class BootstrapApi extends SpringBootServletInitializer {

    public static void main(String[] args) throws Exception {
        System.setProperty("java.net.preferIPv4Stack" , "true");
        SpringApplication app = new SpringApplication(BootstrapApi.class);
        ApplicationContext applicationContext = app.run(args);


        //cacheHandler.initCache();

        //JedisCluster jedisPool =applicationContext.getBean("jedisCluster",JedisCluster.class);

       // String test= jedisPool.get("hello");

       // System.err.println(test);

        /*
        SceneCache cacheHandler=applicationContext.getBean("sceneCache",SceneCache.class);
        cacheHandler.initCache();

        InfoCache infoCache=applicationContext.getBean("infoCache",InfoCache.class);
        infoCache.initCache();*/



        // 启动通知事件的监控
//        EventNotifyRetryScheduling eventNotifyRetryScheduling = (EventNotifyRetryScheduling) applicationContext.getBean("eventNotifyRetryScheduling");
//        eventNotifyRetryScheduling.retryNotifyListener();
    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(applicationClass);
    }

    private static Class<BootstrapApi> applicationClass = BootstrapApi.class;
}